package com.itheima.blockingquene;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Demo01 {

    public static void main(String[] args) throws InterruptedException {
        //队列 : 先进先出
        //数组阻塞队列 底层数组 长度固定 有索引 增删慢 查询快
        //链表阻塞队列 底层链表 增删快 查询慢
       /* ArrayBlockingQueue<String> list = new ArrayBlockingQueue<String>(4);
        list.add("汉堡包");
        list.add("可乐");
        list.add("鸡翅");
        list.add("薯条");
        for (String s : list) {
            System.out.println(s);
        }*/
        LinkedBlockingQueue<String> list = new LinkedBlockingQueue<String>();
        list.add("汉堡包");
        list.add("可乐");
        list.add("鸡翅");
        list.add("薯条");
        for (String s : list) {
            System.out.println(s);
        }


        //啥是阻塞
        //满了 存的人就等着
        //空了 取 的人就等着


        //两个特有的方法
        //put
        list.put("xxx");
        //take
        String take1 = list.take();
        String take2 = list.take();
        String take3 = list.take();
        String take4 = list.take();
        String take5 = list.take();
        System.out.println(take1);
        System.out.println(take2);
        System.out.println(take3);
        System.out.println(take4);
        System.out.println(take5);
        System.out.println(list.take());


    }


}
